﻿//========================================
// All rights reserved (C) 2017-2100
// CLR 版本：	4.0.30319.42000
// 命名空间:	SFJDService.SocketHandle
// 文 件 名：	PH06GetVersion
// 作    者：	WooG
// 联系方式：	wooglle@163.com
// 创建时间：	2017/10/4 18:01:24
//========================================
using System;
using System.Net.Sockets;
using System.IO;
using Network.UpdateData;

namespace SFJDService.SocketHandle
{
    class PH06GetVersion : PacketHandle
    {
        public PH06GetVersion(Socket socket, Packet packet) : base(socket, packet)
        {
        }

        protected override void Handle()
        {
            try
            {
                Runtime.UsersOnLine.HanleActive(guidSend, GetIpSend(), string.Empty);
                FileInfo fileInfo = null;
                Version version = new Version(Message);
                try
                {
                    fileInfo = new FileInfo(Runtime.thisUser.InPath + "Update\\SFJDService.exe");
                }
                catch { }
                Version fileVersion = null;
                if (fileInfo != null && fileInfo.Exists)//如果接收文件夹存在升级文件
                {
                    fileVersion = new Version(System.Diagnostics.FileVersionInfo.GetVersionInfo(Runtime.thisUser.InPath + "Update\\SFJDService.exe").FileVersion);
                }
                if (fileVersion != null && fileVersion > version && fileVersion > Runtime.version)
                {
                    Launcher.SendMsg2All(typeof(PH06GotVersion).GetDictianaryKey(), fileVersion.ToString());
                }
                else if (Runtime.version > version)
                {
                    Launcher.SendMsg2All(typeof(PH06GotVersion).GetDictianaryKey(), Runtime.version.ToString());
                }
            }
            catch
            {
                throw;
            }
            
        }
    }
}
